package com.smartalarmclock.Logic;

import java.util.Set;

import com.smartalarmclock.Model.ContactFactory;
import com.smartalarmclock.Model.ISingleContact;

import android.content.Context;
import android.util.Log;

public class AcAutoResponseService {
	
	public static class AcAutoResponseServiceStatic {
		
		private static final String TAG = "AcAutoResponseServiceStatic";
		public AcAutoResponseServiceStatic() {
			super();
		}

		// TODO: this is just a simple test implementation... Need to handle it correctly (unknown numbers
		// should sometimes also be declined which is currently not convered).
		public static Boolean ShouldDeclineCall(String i_PhoneNumber, StringBuilder o_Response, Context i_Context)
		{
			// TODO: what should really happen here:
			// 1. Get profile of current time frame.
			// 2. Check if the current calling number should be blocked. If so, block it.
			// Instead, right now there is no time frame (UI implementation required). So simply go over all contacts and check if
			// the number equals to any of them. If it is - block it...
			
			Log.v(TAG, "Entered AcAutoResponseService.ShouldDeclineMessage. Phone: " + i_PhoneNumber);
			
			Boolean shouldDeclineMessage = false;			
			ContactFactory contactFactory = new ContactFactory();
			Set<ISingleContact> allContacts = contactFactory.GetAllSingleContacts(i_Context);
			
			for (ISingleContact curContact : allContacts)
			{	
				// TODO: 1. Add a test to actually check profile should block. Right now simply blocks all of them.
				//       2. GetPhoneContactId returns the DB ID of the contact - NOT THE PHONE NUMBER. Should be fixed...
				//       There is no GetPhoneNumber method as of yet...
				
				if (i_PhoneNumber.equals(curContact.GetPhoneContactId()))
				{
					shouldDeclineMessage = true; // FOr test only... should be checked
					o_Response.append("Sleeping, don't wake me up!!!");
					Log.v(TAG, "found it!");
					break;
				}
			}
			
			return shouldDeclineMessage;
		}
		
		public static Boolean ShouldSilenceRinger(String i_PhoneNumber, StringBuilder o_Response, Context i_Context)
		{
			// TODO: same as above... this is only for test...
			Log.v(TAG, "Entered ShouldDeclineMessage. Phone: " + i_PhoneNumber);
			Boolean shouldDeclineMessage = false;
			ContactFactory contactFactory = new ContactFactory();
			Set<ISingleContact> allContacts = contactFactory.GetAllSingleContacts(i_Context);
			
			for (ISingleContact curContact : allContacts)
			{	
				// TODO: 1. Add a test to actually check profile should silence ringer. Right now simply silence all of them.
				//       2. GetPhoneContactId returns the DB ID of the contact - NOT THE PHONE NUMBER. Should be fixed...
				//       There is no GetPhoneNumber method as of yet...
				
				if (i_PhoneNumber.equals(curContact.GetPhoneContactId()))
				{
					shouldDeclineMessage = true; // FOr test only... should be checked
					o_Response.append("Sleeping, don't wake me up!!!");
					Log.v(TAG, "found it!");
					break;
				}
			}
			
			return shouldDeclineMessage;
		}		
	}

}
